.TH "md_docs_2quick__start_2english_203_8getting__start" 3 "common_util" \" -*- nroff -*-
.ad l
.nh
.SH NAME
md_docs_2quick__start_2english_203_8getting__start \- 
.IP "1." 4
Quick Start Guide 
.PP

.PP
 
.SH "1\&.1\&. Overview"
.PP
common_util is a general-purpose C++ utility library, implemented in modern C++ syntax (C++11 and above), using cutl as the namespace\&. The naming convention of all interfaces is consistent with the STL, and it can be used as an extensions of C++ standard library\&. You can use common_util just like using the STL\&.
.SH "1\&.2\&. Directory Structure"
.PP
.PP
.nf
\&./common_util
├── build                       # Cache directory for program building
├── docs                        # Documentation directory
│   ├── quick_start             # Quick Start Guide
│   └── reference               # API interface reference
├── publish                     # Release directory \- stores the final results of the build when using the release configuration
│   ├── common_util             # Published common_util library
│   │   ├── include             # published common_util header files
│   │   └── lib                 # published common_util static library
│   └── common_util_demo        # Published common_util_demo executable program
├── script                      # Script directory
└── src                         # Source code directory
    ├── common_util             # common_util source code directory
    └── usage_demo              # common_util_demo source code directory
.fi
.PP
.SH "1\&.3\&. Usage"
.PP
The simple steps are as follows:
.PP
.RS 4
1\&. Include the \fBcommon_util\&.h\fP header file\&.
.IP "2." 4
Initialize the library and register a callback function for logging\&.
.IP "3." 4
Use the library\&. 
.PP
.RE
.PP
A detail example as follows:
.PP
.PP
.nf
 ++
#pragma once

#include <iostream>
#include <map>
#include <mutex>
#include <thread>
#include "common_util\&.h"

std::string loglevel2flag(cutl::loglevel level)
{
    static std::map<cutl::loglevel, std::string> levelMap = {
        {cutl::loglevel::debug_level, "[D]"},
        {cutl::loglevel::info_level, "[I]"},
        {cutl::loglevel::warn_level, "[W]"},
        {cutl::loglevel::error_level, "[E]"},
    };
    auto itr = levelMap\&.find(level);
    if (itr != levelMap\&.end())
    {
        return itr\->second;
    }
    return "[?]";
}

static std::mutex g_log_mtx_;
void static library_log_func(cutl::loglevel level, const std::string &msg)
{
    std::lock_guard<std::mutex> lock(g_log_mtx_);
    auto curTime = cutl::fmt_timestamp_ms(cutl::timestamp(cutl::timeunit::ms));
    auto threadId = std::this_thread::get_id();
    if (cutl::loglevel::error_level == level)
    {
        std::cerr << "[" << curTime << "]" << loglevel2flag(level) << "]" << threadId << "](cutl) " << msg << std::endl;
    }
    else if (cutl::loglevel::debug_level == level)
    {
        //  print debug log
    }
    else
    {
        std::cout << "[" << curTime << "]" << loglevel2flag(level) << "]" << threadId << "](cutl) " << msg << std::endl;
    }
}

int main(int argc, char *argv[])
{
    // 库的初始化
    cutl::library_init(library_log_func);

    // 数据格式化
    std::cout << "fmt_uint: " << cutl::fmt_uint(12, 5) << std::endl;
    std::cout << "fmt_double: " << cutl::fmt_double(3\&.141592653, 4) << std::endl;
    std::cout << "fmt_filesize: " << cutl::fmt_filesize(33600) << std::endl;
    // 获取系统当前时间
    auto now = cutl::datetime::now();
    std::cout << "current time(UTC time): " << now\&.utctime() << std::endl;
    std::cout << "current time(local time): " << now\&.format() << std::endl;

    return 0;
}
.fi
.PP
.PP
Running result：
.PP
.PP
.nf
[2024\-05\-18 16:01:03\&.477][I]]0x7ff844a9b100](cutl) [config\&.cpp:39:library_init] common_util library initialized, version:1\&.0\&.0
fmt_uint: 00012
fmt_double: 3\&.1416
fmt_filesize: 32\&.8K
current time(UTC time): 2024\-05\-18 08:01:03\&.478
current time(local time): 2024\-05\-18 16:01:03\&.478
.fi
.PP
.SH "1\&.4\&. Demo"
.PP
Directory src/usage_demo contains usage examples for each module\&.
.PP
.PP
.nf
config\&.hpp      # Initialization configuration
datetime\&.hpp    # Usage of the datetime class
filepath\&.hpp    # Usage of the filepath class
fileutil\&.hpp    # File system related operations
strfmt\&.hpp      # String formatting
strutil\&.hpp     # String related operations
sysutil\&.hpp     # System call related operations
timecount\&.hpp   # Function timer class
timeutil\&.hpp    # Time related operations
verutil\&.hpp     # Version number related operations
.fi
.PP
 
